#ifndef SQLFS_H_INCLUDED
#define SQLFS_H_INCLUDED
#include "config.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fuse/fuse.h>
#include <map>
#include <string>
#include <vector>
#include <set>
#include "pool.h"
using namespace std;
class SqlFs {
public:    
	static SqlFs* Get() { return instance ? instance : (instance=new SqlFs()); }
	void setRootDir(const char* path) { rootDir = path; };
    int getattr(const char* path, struct stat* stbuf);
    int access(const char* path, int mask);
    int readdir (const char *path, void *buf, fuse_fill_dir_t filler,
        off_t offset, struct fuse_file_info *fi);
    int mknod (const char *path, mode_t mode, dev_t rdev);
    int mkdir (const char *path, mode_t mode);
    int unlink (const char *path);
    int rmdir (const char *path);
    int symlink (const char *from, const char *to);
    int rename (const char *from, const char *to);
    int link (const char *from, const char *to);
    int chmod (const char *path, mode_t mode);
    int chown (const char *path, uid_t uid, gid_t gid);
    int truncate (const char *path, off_t size);
    int utimens (const char *path, const struct timespec ts[2]);
    int open (const char *path, struct fuse_file_info *fi);
    int read (const char *path, char *buf, size_t size, off_t offset,
	      struct fuse_file_info *fi);
    int write (const char *path, const char *buf, size_t size,
	       off_t offset, struct fuse_file_info *fi);
    int statfs (const char *path, struct statvfs *stbuf);
    int release (const char *path, struct fuse_file_info *fi);
    int fsync (const char *path, int isdatasync, struct fuse_file_info *fi);
    int setxattr (const char *path, const char *name, const char *value,
		  size_t size, int flags);
    int getxattr (const char *path, const char *name, char *value, size_t size);
    int listxattr (const char *path, char *list, size_t size);
    int removexattr (const char *path, const char *name);
	int flush(const char* path, struct fuse_file_info* fi);
	void* init(struct fuse_conn_info* conn);
	int opendir(const char* path, struct fuse_file_info* fi);
	int releasedir(const char* path, struct fuse_file_info* fi);
	int fsyncdir(const char* path, int datasync, struct fuse_file_info* fi);
	void destroy(void* conn);
	int readlink(const char* path, char* target, size_t size);
private:    
	SqlFs(): rootDir("") { p = Pool::Get(); };
	~SqlFs() {};
	SqlFs(const SqlFs&);
	SqlFs& operator=(const SqlFs&);
    bool tableExists(const char* table);
	bool isSqlFsFile(const char* path);
	void getAbsPath(const char* path, string *ret);
    int numTables();
	string rootDir;
	static SqlFs* instance;
	Pool *p;
	set<string> deleted_tables;
};


#endif // SQLFS_H_INCLUDED
